package com.liuanbang.saro.sarodemo.base;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

public class AbstractListViewAdapter extends BaseAdapter {

    protected int templateViewId;

    protected List<Object> operationList;

    public AbstractListViewAdapter(List<Object> operationList, int templateViewId) {
        this.templateViewId = templateViewId;
        this.operationList = operationList;
    }

    @Override
    public int getCount() {
        return operationList != null ? operationList.size() : 0;
    }

    @Override
    public Object getItem(int i) {
        return operationList != null ? operationList.get(i) : null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {
        Object vo = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(this.templateViewId, parent, false);
            vo = getItem(i);
            convertView.setTag(vo);
        } else {
            vo = convertView.getTag();
        }
        //
        return convertView;
    }
}
